<template>
  <div class="nsqaDetail-b ct">
    <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/nsqa' }">农事问答</el-breadcrumb-item>
      <el-breadcrumb-item>问答详情</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="detail-content">
      <div class="content-l">
          <div class="content-head">
            <div class="h3">{{ artice.title }}</div>
            <div class="sp tac" style="padding-top: 10px;">
              {{ artice.releaseTime }} 
              <!-- <span style="padding-left: 10px;">{{artice.publisher}}</span> -->
              </div>
              <!-- 提问者：{{artice.publisher}}次 -->
          </div>


            
          <div class="details">
            <div class="de-img">
              <img :src="artice.avatar || '//xiaoyuan-1309318813.cos.ap-beijing.myqcloud.com/uploads/zizhi/1752077386002WechatIMG4321.jpeg'" alt="">
              <div>{{ artice.publisher }}</div>
            </div>
            <div class="sp" v-for="item in artice._questionDesc">
              <div class="sp" >{{ item }}</div>
            </div>
            <div v-for="itemimage in artice.imageList">
                    <img :src="itemimage" alt=""></img>
                  </div>
            <!-- <div class="details-d" v-html="artice.answer"></div> -->
          </div>

          <div class="comment-list" v-if="comment && comment.total">
            <div class="comment-title">评论（{{artice.commentCount}}）</div>
            <div class="list-data" v-for="item in comment.list">
              <img class="item-img" :src="item.commentAvatar" alt="">
              <div class="item1-left">
                <div class="item-con">
                  <div class="cont-title">{{ item.commentUserName }}
                    <span v-if="item.isExpert" class="zj">专家</span>
                  </div>
                  <div class="cont-con">{{ item.content }}</div>
                  <div class="cont-con2">
                    <div class="list-datai" v-for="sitem in item.subs">
                      <img class="item-img" :src="sitem.commentAvatar" alt="">
                      <div class="item-com2">
                        <div class="cont-title">{{ sitem.commentUserName }}
                          <span v-if="sitem.isExpert" class="zj">专家</span>
                        </div>
                        <div class="cont-con">{{ sitem.content }}</div>
                      </div>
                      <div class="item-tips">
                      <div>{{ sitem.releaseTime }}</div>
                    </div>
                    </div>


                  </div>
                  <div class="cont-ico">
                    <!-- <el-icon><View /></el-icon> -->
                    <!-- <span class="ii">{{ item.pageView }}</span> -->
                    <template v-if="item.likeCount">
                      <el-icon><Star /></el-icon>
                      <span class="ii">{{ item.likeCount }}</span>
                    </template>
              
                  </div>
                </div>
                <div class="item-tips2">
                  <div>{{ item.releaseTime }}</div>
                </div>
              </div>
            </div>
          </div>


        </div>
        <div class="content-r">
          <div>扫描二维码关注更多内容</div>
          <img src="../../assets/job/7.jpg" alt="">
        </div>

    </div>


  </div>
</template>
<script setup>
import { ArrowRight, View, Star } from '@element-plus/icons-vue'
import { getQuestionAnswerById, searchForumComment, getForumById } from '@/api/home';
import { computed, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
const router = useRouter();

const id = computed(() => router?.currentRoute?.value?.params.id)

const artice = ref({});
const comment = ref({});
onMounted(async () => {
  const pls = await searchForumComment({
    params: {
      forumId: id.value,
    },
    page: {
      pageNum: 1,
    }
  })
  console.log('00ret2222', pls)
  if(pls.code == '200' && pls.data) {
    comment.value = pls.data;
    if(pls.data?.list?.length) {
      for(let i = 0; i < pls.data?.list?.length; i++) {
        const commentitem = pls.data?.list[i];
        const ret2 = await searchForumComment({
          params: {
            forumId: id.value,
            commentId: commentitem.commentId
          },
          page: {
            pageNum: 1,
          }
        })
        if(ret2?.code == '200' && ret2.data) {
          comment.value.list[i].subs = ret2.data?.list;
        }
      }
    }
  console.log('00ret2222', comment.value)

  }

  const ret = await getForumById({forumId : id.value })
  console.log('00ret', ret)
  ret.data._questionDesc = ret?.data.content.split(/\n/);
  artice.value = ret?.data;
  


})




</script>
<style lang="scss" scoped>
.nsqaDetail-b {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  color: #777;
  padding: 0 10%;
  .head-nav {
    height: 125px;
    display: flex;
    align-items: center;
    font-size: 24px;
  }
  .detail-content {
    display: flex;
    margin-bottom: 60px;
    flex: 1;
    min-height: 1000px;
    font-family: "SimSun", "宋体", "PingFang SC", "Microsoft YaHei", sans-serif;

    .content-l {
      margin-right: 40px;
      padding: 30px;
      color: #666;
      font-size: 20px;
      min-height: 100%;
      position: relative;
      // padding-bottom: 112px;
      flex: 1;
      overflow: hidden;
      .b-nav {
        color: #666;
        position: absolute;
        height: 112px;
        width: 100%;
        bottom: 0;
        left: 0;
        display: flex;
        align-items: flex-start;
        flex-direction: column;
        justify-content: center;
        padding-left: 30px;
        padding-right: 30px;
        .o {
          width: 100%;
          height: 30px;
          cursor: pointer;
        }
      }

      .content-head {
        padding-bottom: 15px;
      }
      .h3 {
        font-weight: bold;
        font-size: 32px;
        color: #000;
        display: flex;
        justify-content: center;
        
      }
      .sp {
        line-height: 40px;
        //text-indent: 4%;
        font-size: 24px;
      }
      img {
        width: 100%;
        height: 380px;
        object-fit: contain;
        margin: 10px 0;
      }
      .details {
        border-top: 2px solid #e5e5e5;
        border-bottom: 2px solid #e5e5e5;
        padding: 20px;
        background-color: #fff;
        .de-img {
          display: flex;
          align-items: center;
          padding-bottom: 20px;
          font-size: 30px;
          color: #000;
          font-weight: 500;
          img {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            margin-right: 20px;
          }
        }
      }
      :deep(.details-d) {
        p {
          line-height: 32px;
          //text-indent: 4%;
        }
      }
    }
    .content-r {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 20px;
      background-color: #fff;
      align-self: flex-start;
      padding: 20px;
      img {
        width: 300px;
        object-fit: cover;
      }
    }
  }
  .zj {
    font-size: 18px;
    color: #fff;
    background-color: #6bc235;
    padding: 2px 6px;
  }
  .comment-list {
    background-color: #fff;
    // padding: 20px 40px;
    margin-top: 60px;
    .comment-title {
      font-size: 28px;
      color: #333;
      font-weight: 500;
    }
    .list-data {
        display: flex;
        padding: 10px 20px;
        align-items: flex-start;
        position: relative;

        .item-img {
          width: 80px;
          height: 80px;
          border-radius: 50%;
        }
        .item1-left {
          display: flex;
          justify-content: space-between;
          flex: 1;
          .item-tips2 {
            height: 50px;
            position: absolute;
            width: 210px;
            top: 0;
            right: 0;
        }
        }
        .item-con {
          flex: 1;
          overflow: hidden;

          .cont-title {
            padding: 10px 20px;
            font-weight: 500;
            color: #333;
            font-size: 28px;
          }
          .cont-con {
            font-size: 20px;
            padding: 0 20px;
          }
          .cont-ico {
            padding: 5px 20px 0;
            display: flex;
            align-items: center;
            .ii {
              margin-left: 10px;
              margin-right: 10px;
            }
          }
          .list-datai {
            display: flex;
            padding: 0px 20px;
            margin-top: 20px;
            padding-left: 10px;
            .item-img {
              width: 80px;
              height: 80px;
              border-radius: 50%;
            }
            .item-com2 {
              flex: 1;
            }
       
          }
      
        }

      }
  }
}
</style>